<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.Project"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="db.ProjectDAO"%>
<%@page import="db.SubstoreDAO" %>
<%@page import="db.PurreqDAO" %>
<%@page import="db.Purreq" %>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.io.File"%>
<%@page import="java.util.*"%>
<%@page import="javazoom.upload.*"%> 
<%@page import="uploadutilities.FileMover"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="jxl.Cell"%>
<%@page import="jxl.Sheet"%>
<%@page import="jxl.Workbook"%>
<%@page import="jxl.WorkbookSettings"%>
<%@page import="db.FororderDAO"%>
<%@page import="db.Fororder"%>
<%@page import="db.Supplier"%>
<%@page import="db.SupplierDAO"%>
<%@page import="db.MaterialDAO"%>
<%@page import="db.Material"%>
<%@page import="db.ForderpurmatDAO"%>
<%@page import="db.Receiveorder"%>
<%@page import="db.ReceiveorderDAO"%>
<%@page import="db.Group" %>
<%@page import="db.Receivepurmat"%>
<%@page import="db.ReceivepurmatDAO"%>
<%@page import="db.Place"%>
<%@page import="db.PlaceDAO"%>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%@ include file="/jsp/common/utility/ImportExecl.jsp" %>
<%
	request.setCharacterEncoding("utf-8");
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	MaterialDAO materialDAO = (MaterialDAO)ctx.getBean("MaterialDAO");
	UserDAO userDAO = (UserDAO)ctx.getBean("UserDAO");
	PlaceDAO placeDAO = (PlaceDAO)ctx.getBean("PlaceDAO");
	ProjectDAO projectDAO = (ProjectDAO)ctx.getBean("ProjectDAO");
	ReceiveorderDAO receiveorderDAO = (ReceiveorderDAO)ctx.getBean("ReceiveorderDAO");
	ReceivepurmatDAO receivepurmatDAO = (ReceivepurmatDAO)ctx.getBean("ReceivepurmatDAO");
	ForderpurmatDAO forderpurmatDAO = (ForderpurmatDAO)ctx.getBean("ForderpurmatDAO");
	SupplierDAO supplierDao = (SupplierDAO)ctx.getBean("SupplierDAO");
	int uid = 0 ;
	if(session.getAttribute("id")!=null){
		uid = (Integer)session.getAttribute("id");
	}
	FileMover fileMover = new FileMover();//你也可以使用自带的实例中jsp:useBean的形式。
	UploadBean upBean = new UploadBean();
	MultipartFormDataRequest mrequest = null;
	int tid = (Integer)session.getAttribute("tid");
	Hashtable files = null;
	boolean success = true;
	String message = "恭喜您，批量入库成功！";
	String serverPath = new String();
	serverPath = request.getParameter("serverPath");
	List listjxl = new ArrayList();
	if(serverPath!=null){
		listjxl = getListByJxl(serverPath,success,message);
		request.setAttribute("serverPath",serverPath);
	}
	List listmap = new ArrayList();
	
	if(listjxl!=null && listjxl.size()>0){
		for(int i=0;i<listjxl.size();i++){
			List li = (List)listjxl.get(i);
			if(li!=null && li.size()>=4){
				Supplier supplier = new Supplier();
				supplier.setDate(new Date());
				supplier.setIsDelete(0);
				supplier.setName((String)li.get(0));
				supplier.setPerson((String)li.get(1));
				supplier.setPhone((String)li.get(2));
				supplier.setTeamId(tid);
				supplier.setRemark((String)li.get(3));
				supplierDao.save(supplier);
			}else{
				success = false;
				message = "解析出错，execl文件格式行数不够，请仔细检查execl文件。";
				request.setAttribute("success",success);
				request.setAttribute("message",message);
				pageContext.forward("/vm/supinfo/supinfoImportExecl.vm");
				return;
			}
			
			
		}
	}
	request.setAttribute("listjxl",listmap);
	request.setAttribute("success",success);
	request.setAttribute("message",message);
	pageContext.forward("/vm/supinfo/supinfoImportExecl.vm");
%>